<template>
    <div class="withPlay" v-if="gamestatus.isWithPlay.userName">
    <div class="content">
        
        <h2>{{gamestatus.isWithPlay.userName}}邀请你一起玩</h2>
        <button @click="rejection">拒绝</button>
        <button @click="agree">同意</button>
    </div>
    </div>
</template>
<script setup>
import { useRouter } from "vue-router";
import useGamestatus from "../stores/game";
import {useUserStore} from "../stores/user";

const router = useRouter();
const gamestatus = useGamestatus();
let userStore = useUserStore();

function rejection(){
    router.push("/lobby");
    gamestatus.isWithPlay = {};
    console.log("拒绝");
};
function agree(){
    gamestatus.socket.emit("joinRoom", { roomId: gamestatus.isWithPlay.roomId, sid: gamestatus.sid,userId:userStore.user.userId });
    gamestatus.isWithPlay = {};
    console.log("同意");
}
</script>
<style scoped>
.withPlay {
    width:100vw;
    height:100vh;
    display:flex;
    justify-content:center;
    align-items:center;
    position:fixed;
    top:0;
    left:0;
    z-index:9999;
    background-color:rgba(0,0,0,0.5);
}

.content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 90%;
    width: 400px;
}

h2 {
    color: #333;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

button {
    padding: 0.75rem 1.5rem;
    margin: 0 0.5rem;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

button:first-of-type {
    background: #f0f0f0;
    color: #333;
}

button:first-of-type:hover {
    background: #e0e0e0;
}

button:last-of-type {
    background: #4CAF50;
    color: white;
}

button:last-of-type:hover {
    background: #45a049;
}
</style>